<?php
/**
**2015-10-20 对接天时同城切换两次交互模式
**User By  PZP
**/
include('/var/www/html/new/d/module/api/TianShiTongCheng/tstc.class.php');
include('/var/www/html/new/d/module/api/function.class.php');

$ac='16ucom';
$pw='c33367701511b4f6020ec61ded352059';
$inSide = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}

$PFT_infunction = new AllFunction(); 
$PFT_infunction->logfile('10|'.json_encode($_REQUEST),'get_data');

// http://www.12301.cc/module/api/TianShiTongCheng/tstc_get_data.php?Tnum=1&Fid=113&PayStatus=1&TicketID=26158&TouristName=pzp&TouristTel=15959110796&PlayDate=2015-10-20 00:00:00&IdCard=350321199108230123
// http://www.12301.cc/module/api/ZhiYouBao/zyb_get_data.php?Tnum=0&Action=MOD&Ordern=2341346



if(!isset($_REQUEST['Action'])){	

	if(!$_REQUEST['TicketID']) exit("101");
	
	$tid = $_REQUEST['TicketID'] + 0;

	$select_uuid = "select t.uuid,t.pid,t.title as ttitle,t.landid,l.title as ltitle,l.apply_did,m.account from uu_jq_ticket as t, uu_land as l,pft_member as m where t.id=$tid  and t.landid=l.id and l.apply_did=m.id  limit 1";
	$GLOBALS['le']->query($select_uuid);
	if(!$GLOBALS['le']->fetch_assoc())	exit("101");		
	$uuid = $GLOBALS['le']->f('uuid');  //查询票类id	
	$apply_did = $GLOBALS['le']->f('apply_did'); 

	$tstc = new TianShiTongCheng($tid,$apply_did);

	$ispay = $_REQUEST['PayStatus'] == 1 ? 1 : 0 ;

	$ls_order = 'pft'.str_replace('.',mt_rand(1000,9999),microtime(true));	
	$request_array = array(
		'ispay'			=> $ispay,
		'pftordernum' 	=> $ls_order,
		'uuid'			=> $uuid,	
		'pftordername' 	=> $_REQUEST['TouristName'],
		'UUordertel'	=> $_REQUEST['TouristTel'],
		'IDcar'			=> $_REQUEST['IdCard'],
		'UUtnum' 		=> $_REQUEST['Tnum'],
		'UUplaytime'	=> substr($_REQUEST['PlayDate'],0,10),		
	);
	$request = $tstc->Submit_Order($request_array,$PFT_infunction);
	if($request == 101) exit("101|0|0|0|0|0");
	else exit("200|0|0|0|".$request['tstc_ordercode']."|".$request['tstc_orderid'].'_'.$ls_order);
	
}elseif($_REQUEST['Action'] == 'Relation'){ //下单成功

	$Ordern = $_REQUEST['Ordern'];
	$pft_order_xml = $PFT_infunction->Select_PFTorder($_REQUEST['Ordern']);
	$tnum = (int)$pft_order_xml->Rec->UUtnum;
	$UUpaystatus = (int)$pft_order_xml->Rec->UUpaystatus;
	$apiCode = (string)$pft_order_xml->Rec->UUvcode;
	$tordernums = explode('_',(string)$pft_order_xml->Rec->UUtordernum);
	$apiOrder = $tordernums['0'];
	$tempOrder = $tordernums['1'];
	
	$str="insert into all_api_order (pftOrder,apiOrder,tempOrder,coopB,oStatus,oStnum,apiCode,handleStatus,cTime) values('$Ordern','$apiOrder','$tempOrder',10,0,$tnum,'$apiCode',0,now())";
	$GLOBALS['le']->query($str);
	
}elseif($_REQUEST['Action'] == 'MOD'){//取消订单
	$pftOrder = $_REQUEST['Ordern'];
	$selapiOrder = "select apiOrder,tempOrder,handleStatus,oStatus,oStnum from all_api_order where pftOrder='$pftOrder' limit 1";
	$GLOBALS['le']->query($selapiOrder);
	if(!$GLOBALS['le']->fetch_assoc())	exit('105');
	$handleStatus = $GLOBALS['le']->f('handleStatus');
	$tempOrder = $GLOBALS['le']->f('tempOrder');
	$apiOrder = $GLOBALS['le']->f('apiOrder');
	$oStatus = $GLOBALS['le']->f('oStatus');
	$tnum = $GLOBALS['le']->f('oStnum');
	
	$pft_order_xml = $PFT_infunction->Select_PFTorder($pftOrder);
	$UUaids= (string)$pft_order_xml->Rec->UUaids;
	$UUtid= (int)$pft_order_xml->Rec->UUtid;
	if($UUaids == 0){
		$UUaid = (int)$pft_order_xml->Rec->UUaid;
	}else{
		$UUaidss= explode(',',$UUaids);
		$UUaid = $UUaidss[0];
	}
	
	$tstc = new TianShiTongCheng($UUtid,$UUaid);
	
	if($_REQUEST['Tnum'] == 0) $size = '';
	else $size = $tnum - $_REQUEST['Tnum'];
	
	$result = $tstc->Modify_Order($size,$apiOrder,$tempOrder,$pftOrder,$PFT_infunction);
	if($result == 101) exit("1077|0|0|0");
	else{
		$upoStatus = $_REQUEST['Tnum'] == 0 ? 3 : 4;
		$selorder = "update all_api_order set oStatus = $upoStatus,oStnum=".$_REQUEST['Tnum']." where pftOrder='$pftOrder' limit 1";
		$GLOBALS['le']->query($selorder);
		exit("200|0|0|0");
	}
}
?>